package com.gitee.cui.client.command;

import lombok.Data;
import org.springframework.stereotype.Service;

import java.util.Scanner;

/**
 * 聊天指令处理类
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021/10/27 14:43
 **/
@Data
@Service
public class ChatConsoleCommand implements BaseCommand {

    /**
     * 聊天指令key
     */
    public static final String KEY = "2";

    /**
     * 聊天对方id
     */
    private String toUserId;

    /**
     * 聊天的信息
     */
    private String message;

    @Override
    public String getKey() {
        return KEY;
    }

    @Override
    public String getTip() {
        return "聊天";
    }

    @Override
    public void exec(Scanner scanner) {
        System.out.println("请输入聊天的消息(id@message): ");
        String[] info = null;
        while (true) {
            String input = scanner.next();
            info = input.split("@");
            if (info.length != 2) {
                System.out.println("请输入正确格式的聊天消息(id@message): ");
            } else {
                break;
            }
        }
        toUserId = info[0];
        message = info[1];
    }
}
